#include"DB.h"
constexpr auto LOWRATE = 0.33;
constexpr auto MIDRATE = 0.67;
constexpr auto HIGHRATE = 1.0;

PaymentList::PaymentList(int roomId, int listId, std::vector<reqPayment*>req) {
	time = std::time(NULL);
	type = Type::RESPONSE;
	responseType = 1;
	this->roomId = roomId;
	this->listId = listId;
	totalFee = settotalFee(req);
}
time_t PaymentList::gettime(void) {
	return time;
}
Type PaymentList::gettype(void) {
	return type;
}
int PaymentList::getresponseType(void) {
	return responseType;
}
int PaymentList::getlistId(void) {
	return listId;
}
int PaymentList::getroomId(void) {
	return roomId;
}
double PaymentList::gettotalFee(void) {
	return totalFee;
}
double PaymentList::settotalFee(std::vector<reqPayment*>req) {
	if ((int)req.size() == 0) {
		std::cout << "The roomId doesn't exist!" << std::endl;
		return 0.0;
	}
	//���֣����req�������������������ڷ������
	double sumFee = 0.0;
	double rate = 0.0;
	if (req.size() % 2 == 1) {
		for (int i = 0; i < (int)req.size() / 2 + 1; ++i) {
			if (req[2 * i]->wd == WindMood::LOW) {
				rate = LOWRATE;
			}
			else if (req[2 * i]->wd == WindMood::MEDIUM) {
				rate = MIDRATE;
			}
			else if (req[2 * i]->wd == WindMood::HIGH) {
				rate = HIGHRATE;
			}
			else {
				std::cout << "����д����" << std::endl;
			}
			if (i < (int)req.size() / 2) {
				sumFee += (req[2 * i + 1]->time - req[2 * i]->time) * rate;
			}
			else {
				int nowTime = (int)std::time(NULL);
				sumFee += (nowTime - req[2 * i]->time) * rate;
			}
		}
	}
	//ż������������
	else {
		for (int i = 0; i < (int)req.size() / 2; ++i) {
			if (req[2 * i]->wd == WindMood::LOW) {
				rate = LOWRATE;
			}
			else if (req[2 * i]->wd == WindMood::MEDIUM) {
				rate = MIDRATE;
			}
			else if (req[2 * i]->wd == WindMood::HIGH) {
				rate = HIGHRATE;
			}
			else {
				std::cout << "����д����" << std::endl;
			}
			sumFee += (req[2 * i + 1]->time - req[2 * i]->time) * rate;
		}
	}
	return sumFee;
}
